package com.gsoe.auth.service.impl;

import cn.dev33.satoken.SaManager;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gsoe.auth.po.Role;
import com.gsoe.auth.mapper.RoleMapper;
import com.gsoe.auth.po.RolePower;
import com.gsoe.auth.po.UserRole;
import com.gsoe.auth.service.RolePowerService;
import com.gsoe.auth.service.RoleService;
import com.gsoe.auth.service.UserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 角色表 服务实现类
 * </p>
 *
 * @author xiaoma
 * @since 2024-11-11
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {
    @Autowired
    private RolePowerService rolePowerService;
    @Autowired
    private UserRoleService userRoleService;

    @Override
    public void delRole(Long roleId) {
        Role role = getById(roleId);
        if(role==null){return;}
        removeById(roleId);
        rolePowerService.remove(new QueryWrapper<RolePower>().eq("role_id", roleId));
        userRoleService.remove(new QueryWrapper<UserRole>().eq("user_id", roleId));
        SaManager.getSaTokenDao().deleteObject("satoken:role-find-permission:"+role.getRoleName());
    }
}
